package com.dc.enums;

import org.apache.commons.lang3.StringUtils;

/**
 * 设备状态
 */
public enum DeviceStatusType {

    NORMAL(0, "正常"),

    FAULT(1, "故障"),

    SUPERVISE(2, "监管"),

    WORK(3, "工作");


    private Integer id;
    private String name;


    DeviceStatusType(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    public static DeviceStatusType getId(Integer id) {
        for (DeviceStatusType v : values()) {
            if (v.id == id) {
                return v;
            }
        }
        return null;
    }

    /**
     * 比较枚举值是否相等
     *
     * @param id 枚举值
     * @return
     */
    public boolean equalsId(Integer id) {
        if (this.id.equals(id)) {
            return true;
        }
        return false;
    }


    /**
     * 根据枚举id值获取name值
     *
     * @param id 枚举id值
     * @return
     */
    public static String getNameById(String id) {
        if (StringUtils.isBlank(id)) {
            return null;
        }
        for (DeviceStatusType value : DeviceStatusType.values()) {
            if (value.getId().toString().equals(id)) {
                return value.getName();
            }
        }
        return null;
    }


    public Integer getId() {
        return id;
    }

    public String getName() {
        return name;
    }
}
